home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_8.zip / CWKGRAPH.C < prev    next >
C/C++ Source or Header  |  1993-12-29  |  25KB  |  935 lines

  1.  
  2.  
  3. /*
  4.     GWMON Parallel Ada Monitor for 386/486 PCs   
  5.     Copyright (C) 1993, Charles W. Kann  & Michael Bliss Feldman
  6.                         ckann@seas.gwu.edu mfeldman@seas.gwu.edu
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include "ed.h"
  24. #include "keydef.h"
  25.  
  26. #if 0
  27. #define ROWS 10
  28. #endif
  29. static int ROWS = 10;
  30. #define COLS 78
  31. #define MAX_WINDOWS 12
  32. static char video[4000];
  33. static AVL_WIN_PTR  top_win, output_win;
  34. static struct rccoord text_pos;
  35. static int next_monitor;
  36. static int SAVE_WIN_SIZE;
  37.  
  38. /*
  39.    Structures for Block names for monitor windows titles.  Note that the
  40.    Block names structure does not malloc the names.  I was afraid that
  41.    malloc would fragment core too much with alot of funny sized pieces of
  42.    memory.
  43. */
  44.  
  45. #define MAX_LEVELS 200
  46. #define NAME_SIZE 32
  47. static char Block_Name[MAX_LEVELS][NAME_SIZE];
  48.  
  49. #define NEWLINE 0x0a
  50. #define ESCAPE 0x1b
  51.  
  52. void CWK_DEL_WINDOW();
  53. static struct {
  54.     AVL_WIN_PTR w;
  55.     int used;
  56.     COORD wind_coord;
  57.     int monitor;
  58. } window[MAX_WINDOWS];
  59.     
  60. static int SCROLL_LINE = 0, escape_sequence = 0;
  61.  
  62. void CWK_ERASE_ALL_MON_WIN();
  63. void CWK_ERASE_MON_WIN();
  64. void CWK_CLEANUP_MON();
  65.  
  66. CWK_MOVE_INPUT( fp )
  67. FILE *fp;
  68. {
  69.     struct rccoord text_p;
  70.     if ( ! isatty( fileno(fp) )) 
  71.     return;
  72.  
  73.  
  74.     text_p= _gettextposition();
  75.     text_p.col = 1;
  76.     text_p.row++;
  77.     if (text_p.row >= ROWS) {
  78.         SCROLL_LINE = 1;
  79.     text_p.row--;
  80.         }
  81.     _settextposition(text_p.row, text_p.col);
  82. }
  83.  
  84. CWK_PUTC( inchar, fp )
  85. int inchar;
  86. FILE *fp;
  87. {
  88.     struct rccoord text_p;
  89.     static int screen_row, screen_col;
  90.     static char next_char;
  91.     char TextString[2];
  92.  
  93.     /*
  94.     if this file is not a tty, write the character and continue
  95.     */
  96.  
  97.     if ( ! isatty( fileno(fp) )) {
  98.     fputc(inchar,fp);fflush(fp);
  99.     return;
  100.      }
  101.  
  102.  
  103.     /*
  104.     Cheap kludge to handle ascii control sequences
  105.     */
  106.  
  107.     if ( escape_sequence ) {
  108.     switch ( next_char ) {
  109.        case '[' :
  110.         if ( inchar == '[' ) {
  111.             next_char = '1';
  112.             return;
  113.         }
  114.         break;
  115.        case '1' :
  116.         if ( inchar == 'J' ) {
  117.             int i;
  118.             char buf[80];
  119.  
  120.             escape_sequence = 0;
  121.             sprintf(buf,"%-78s"," ");
  122.             for(i = 1; i <= ROWS; ++i) {
  123.                 _settextposition(i, 1 );
  124.                 _outtext(buf);
  125.             }
  126.             _settextposition(1, 1 );
  127.             return;
  128.         }
  129.         else if ( inchar == ';' ) {
  130.             next_char = '2';
  131.             return;
  132.         }
  133.         else if (isdigit( inchar )) {
  134.             screen_row = screen_row * 10 + (inchar - '0');
  135.             return;
  136.         }
  137.         break;
  138.         case '2' :
  139.         if ( inchar == 'f' ) {
  140.             escape_sequence = 0;
  141.                 _settextposition(screen_row, screen_col);
  142.             return;
  143.         }
  144.         else if ( isdigit( inchar )) {
  145.             screen_col = screen_col * 10 + (inchar - '0');
  146.             return;
  147.         }
  148.         break;
  149.         default:
  150.         break;
  151.     }
  152.     escape_sequence = 0;
  153.     }
  154.  
  155.     if ( inchar != ESCAPE ) {
  156.         text_p= _gettextposition();
  157.         if ( SCROLL_LINE ) {
  158.             _scrolltextwindow(_GSCROLLUP);
  159.         SCROLL_LINE = 0;
  160.             }
  161.     }
  162.  
  163.     if ( inchar == ESCAPE ) {
  164.     SCROLL_LINE = 0;
  165.     escape_sequence = 1;
  166.     screen_row = screen_col = 0;
  167.     next_char = '[';
  168.     return;
  169.     }
  170.  
  171.     else if ( ( inchar == NEWLINE ) || ( inchar == CTRL_M ) ) {
  172.     text_p.col = 1;
  173.     text_p.row++;
  174.         if (text_p.row >= ROWS) {
  175.             SCROLL_LINE = 1;
  176.         text_p.row--;
  177.             }
  178.         }
  179.     else {
  180.         sprintf( TextString, "%c", inchar );
  181.         _outtext( TextString );
  182.         text_p.col++;
  183.     if (  text_p.col > COLS ) {
  184.         text_p.col = 1;
  185.         text_p.row++;
  186.         }
  187.     }
  188.     if (text_p.row >= ROWS) {
  189.         SCROLL_LINE = 1;
  190.     text_p.row--;
  191.         }
  192.     _settextposition(text_p.row, text_p.col);
  193. }
  194.  
  195. static int CWK_MON_GET_WIN(monitor)
  196. int monitor;
  197. {
  198.     int i;
  199.     static int last_used;
  200.     
  201.     for (i = 0; i < Windows_Used; i++) {
  202.         if ( ! window[i].used ) {
  203.         window[i].used = 1;
  204.         window[i].monitor = monitor;
  205.         last_used = i;
  206.         return i;
  207.         }
  208.         }
  209.     return -1;
  210.     
  211. }
  212.  
  213. static void CWK_MAKE_WINDOW(title, win_no)
  214. char *title;
  215. int win_no;
  216. {
  217.     window[win_no].w = AVL_MAKE_WINDOW( title, window[win_no].wind_coord.x1,
  218.                 window[win_no].wind_coord.y1, 
  219.                 window[win_no].wind_coord.x2, 
  220.                 window[win_no].wind_coord.y2, 
  221.                 1, 15 );
  222. }
  223.  
  224. static void CWK_SAVE_TEXT_POS()
  225. {
  226.     text_pos = _gettextposition();
  227. }
  228.     
  229. static void CWK_RES_TEXT_POS()
  230. {
  231.     _settextwindow(2,2,ROWS,79);
  232.     _settextposition(text_pos.row, text_pos.col);
  233. }
  234.  
  235. MON_REC_PTR CWK_CREATE_MON_WIN( title, display )
  236. char *title;
  237. int display;
  238. {
  239.     CWK_SAVE_TEXT_POS();
  240.     CWK_MONS[next_monitor].title = malloc( strlen( title ) + 1 );
  241.     strcpy( CWK_MONS[next_monitor].title, title );
  242.     if ( display )
  243.     {
  244.         CWK_MONS[next_monitor].mon_win = CWK_MON_GET_WIN(next_monitor);
  245.         if (CWK_MONS[next_monitor].mon_win == -1)
  246.         {
  247.         CWK_MONS[next_monitor].WON = -1;
  248.         }
  249.         else
  250.         {
  251.         CWK_MONS[next_monitor].WON = 1;
  252.         CWK_MAKE_WINDOW( title, CWK_MONS[next_monitor].mon_win );
  253.         }
  254.     }
  255.     else
  256.         CWK_MONS[next_monitor].WON = -1;
  257.  
  258.     CWK_RES_TEXT_POS();
  259.     return &CWK_MONS[next_monitor++];
  260. }
  261.  
  262. /*************************************************************************/
  263. /*    Routines to draw the monitor windows                             */
  264. /*************************************************************************/
  265. void CWK_REMOVE_BLOCK ( tmp_mon )
  266. MON_REC *tmp_mon;
  267. {
  268.     CWK_SAVE_TEXT_POS();
  269.  
  270.     CWK_ERASE_MON_WIN(tmp_mon);
  271.  
  272.      Block_Level--;
  273.      if ( Block_Level < 0 )
  274.      {
  275.         char msg[80];
  276.             sprintf( msg, "Internal Error, leaving too many blocks" );
  277.         CWK_CLEANUP_MON( -1, msg );
  278.     }
  279.     *Block_Name[Block_Level] = '\0';
  280.     CWK_RES_TEXT_POS();
  281. }
  282.  
  283. void CWK_DRAW_PROC_WIN( tmp_mon, enter_or_exit )
  284. MON_REC *tmp_mon;
  285. int enter_or_exit;
  286. {
  287.     int i, First_Win_On_Screen;
  288.  
  289.     CWK_SAVE_TEXT_POS();
  290.  
  291.     if ( ! enter_or_exit )
  292.     {
  293.         strcpy( Block_Name[Block_Level], tmp_mon->title );
  294.         Block_Level++;  
  295.     }
  296.     
  297.  
  298.     if ( Block_Level >= Windows_Used )
  299.     {
  300.         WIN_SIZE = SAVE_WIN_SIZE - Windows_Used;
  301.         tmp_mon->mon_win = Windows_Used - 1;
  302.         First_Win_On_Screen = Block_Level - Windows_Used;
  303.         CWK_ERASE_ALL_MON_WIN();
  304.         tmp_mon->WON = 1;
  305.         for ( i = 0; i < Windows_Used; ++i )
  306.         {
  307.         window[i].used = 1;
  308.             CWK_MAKE_WINDOW( Block_Name[First_Win_On_Screen+i], i );
  309.         }
  310.     }
  311.     else if ( Block_Level > 0 )
  312.     {
  313.         WIN_SIZE = SAVE_WIN_SIZE - Block_Level;
  314.         tmp_mon->mon_win = Block_Level - 1;
  315.         if ( enter_or_exit )
  316.             CWK_ERASE_MON_WIN(tmp_mon);
  317.         window[Block_Level-1].used = 1;
  318.         tmp_mon->WON = 1;
  319.         CWK_MAKE_WINDOW( Block_Name[Block_Level-1], Block_Level-1);
  320.     }
  321.  
  322.     CWK_RES_TEXT_POS();
  323.  
  324.     /*
  325.         Note that we have to redraw the time, otherwise it
  326.         doesn't look right.
  327.     */
  328.     CWK_REPORT_TIME(Run_Total_Time);
  329. }
  330.  
  331. void CWK_DRAW_MON_WIN(tmp_mon)
  332. MON_REC   *tmp_mon;
  333. {
  334.     CWK_SAVE_TEXT_POS();
  335.     tmp_mon->mon_win = CWK_MON_GET_WIN(next_monitor);
  336.     if (tmp_mon->mon_win == -1)
  337.     {
  338.         tmp_mon->WON = -1;
  339.     }
  340.     else
  341.     {
  342.         tmp_mon->WON = 1;
  343.         CWK_MAKE_WINDOW( tmp_mon->title, tmp_mon->mon_win );
  344.     }
  345.     CWK_RES_TEXT_POS();
  346.  
  347. void CWK_ERASE_ALL_MON_WIN()
  348. {
  349.     int i;
  350.     CWK_SAVE_TEXT_POS();
  351.     for (i = MAX_WINDOWS - 1; i >= 0; i--) {
  352.         if ( window[i].used ) {
  353.         window[i].used = 0;
  354.         window[i].monitor = -1;
  355.         CWK_DEL_WINDOW(i); 
  356.         }
  357.         }
  358.     CWK_RES_TEXT_POS();
  359. }
  360.  
  361. void CWK_ERASE_MON_WIN(tmp_mon)
  362. MON_REC   *tmp_mon;
  363. {
  364. #if 0
  365.     {
  366.     char msg[80];
  367.     sprintf( msg, " in erase_mon_win, name = %s, used =%d\n", 
  368.         tmp_mon->title, window[tmp_mon->mon_win].used );
  369.     _outtext(msg);